package org.example.Soution002;

public class SearchNum {
    public static void main(String[] args) {
        int nums[][]=new int[][]{{1,3,5,7},{10,11,16,20},{23,30,34,60}};
        SearchNum obj=new SearchNum();
        System.out.println(obj.searchMatrix(nums,13));

    }

    public boolean searchMatrix(int[][] matrix, int target) {
        int start=0;int end=matrix[0].length-1;
        for(int i=0;i<matrix.length;i++){
            if(target<matrix[i][start]){
                return false;
            }else if(target>matrix[i][end]){
                continue;
            }
            return findTarget(matrix[i],target);
        }
        return false;
    }

    public boolean findTarget(int[] nums, int target) {
        int low=0;int high=nums.length-1;
        while(low<=high){
            int mid=(low+high)/2;
            if(nums[mid]==target){
                return true;
            }else if(nums[mid]>target){
                high=mid-1;
            }else{
                low=mid+1;
            }
        }
        return false;
    }
}
